import time

def getDataFromFile(file_name: str):
    _list = []
    with open(file_name, 'r') as file:
        for line in file.readlines():
            _list.append(int(line.replace('\n', '')))
        
        return _list

m1_sorted = getDataFromFile('data/m1_sorted.txt')
m2_reverse = getDataFromFile('data/m2_reverse.txt')
m3_shuffle = getDataFromFile('data/m3_shuffle.txt')

def bubbleSort(data: list):
    swapped = False

    for i in range(len(data) - 1, 0, -1):
        for j in range(i):
            if data[j] > data[j + 1]:
                data[j], data[j + 1] = data[j + 1], data[j]
                swapped = True
        if swapped:
            swapped = False
        else:
            break
    
    return data

start_time = time.time()
bubbleSort(m1_sorted)
end_time = time.time()
execution_time = (end_time - start_time) * 1000
print(f'm1_sorted {execution_time:.5f} milliseconds')

start_time = time.time()
bubbleSort(m2_reverse)
end_time = time.time()
execution_time = (end_time - start_time) * 1000
print(f'm2_reverse {execution_time:.5f} milliseconds')

start_time = time.time()
bubbleSort(m3_shuffle)   
end_time = time.time()
execution_time = (end_time - start_time) * 1000
print(f'm3_shuffle {execution_time:.5f} milliseconds')